#ifndef COMMON_APPLICATION_H
#define COMMON_APPLICATION_H

#include <glad\glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include "GuiLayer.h"
#include "SampleSelector.h"

namespace RayTracer {

struct WindowParam {
    WindowParam(std::string name = "RayTracer", int width = 1280, int height = 960, bool isFullScreen = true)  
        : mWindowName(name), mWidth(width), mHeight(height), mIsFullScreen(isFullScreen)
    {}
    std::string mWindowName;
    int mWidth;
    int mHeight;
    bool mIsFullScreen;
};

static void glfw_error_callback(int error, const char* description) {
    fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GLFW_TRUE);
}

class Application {
 public:
    ~Application();
    void Run();

    static Application* msInstance;
    static Application* GetInstance();
    GLFWwindow* GetWinowHandle();
    GuiLayer* GetGuiHandle();
    void SetParam(WindowParam param);
    void InitApplication();

    GLuint GetTexHandle() { return mTexID; }
    void SetTexHandle(GLuint texId) { mTexID = texId; }

    void SetImageViewerName(std::string name) { mViewerName = name; }
    std::string GetViewerName() { return mViewerName; }
 private:
     Application();
     bool CreateWindow();
     void DestroyWindow();
 private:
     GLFWwindow* mWindowHandle = nullptr;
     GuiLayer* mImGuiLayer = nullptr;
     WindowParam mWindowParam;
     bool mIsRunning = false;
     ImVec4 clear_color = ImVec4(0.144f, 0.668f, 0.931f, 1.000f);
     SampleSelector* mSelector = nullptr;
     GLuint mTexID = 0;
     std::string mViewerName = std::string("Image");
};

}
#endif // !COMMON_APPLICATION_H


